import grok
from zope import interface, schema

from app import datetimewidget_test

class IPerson(interface.Interface):
    name = schema.TextLine(title=u"Name")
    birthday = schema.Date(title=u"Birth Day")
    birthdatetime = schema.Datetime(title=u"Birth Date and Time")

class Person(grok.Model):
    interface.implements(IPerson)

    def __init__(self, name, birthday, birthdatetime):
        self.name = name
        self.birthday = birthday
        self.birthdatetime = birthdatetime

class AddPerson(grok.AddForm):
    grok.context(datetimewidget_test)
 
    form_fields = grok.AutoFields(IPerson)
    
    grok.action('Add Person')
    def add(self, **data):
        obj = Person(**data)
        name = data['name'].lower().replace(' ', '_')
        self.context[name] = obj

class Index(grok.DisplayForm):
    pass